package com.linln.wxapi;

import com.linln.common.utils.ResultVoUtil;
import com.linln.common.vo.ResultVo;
import com.linln.modules.member.domain.MemberShare;
import com.linln.modules.member.domain.MemberZan;
import com.linln.modules.member.service.MemberShareService;
import com.linln.modules.member.service.MemberZanService;
import com.linln.modules.tribe.service.TribeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(value="点赞接口")
@RestController
@RequestMapping("/wx/memberzan/{area}")
public class WxApiMemberZanController {

	   @Autowired
	   private MemberZanService memberZanService;

    @Autowired
    private TribeService tribeService;



    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	  
	 /**
	  *   /** 商户 */
	    //   index  =0首页
	   //    STORE = 2;
	   //MESSAGE = 1;
	   // AD = 3;
      // AGENT = 6;  
	   //4是论坛
	   //其他5
	
    @ApiOperation(value = "点赞接口",  notes = "点赞接口")
    @RequestMapping(value = "addZan",method={RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public ResultVo addZan(@PathVariable String area,Integer type,Long typeId,Long memberId) {
        try {
        	System.out.println("我的share.........");
        	MemberZan memberZan=new MemberZan();
            memberZan.setArea(area);
            memberZan.setCreateDate(new Date());
            memberZan.setMemberId(memberId);
            memberZan.setType(type);
            memberZan.setTypeId(typeId);
            memberZan.setUpdateDate(new Date());
            memberZan=memberZanService.save(memberZan);
            if(memberZan.getId()>0) {
             if(type!=null && type.intValue()==4){
                 //给部落内容增加赞的数量
                 tribeService.updateIsZanAddById(typeId);
             }
             return ResultVoUtil.success("点赞成功");
            }else {
                return ResultVoUtil.success("点赞失败");

            }
        } catch (Exception e) {
            this.logger.error(e.getMessage(), e);
            return ResultVoUtil.error("接口异常"); 
        } 
    }
	
}


